<template>
	<div class="popup-content">
		<header class="popup-title">
			<span>{{
				$t('pages.application.ApplicationClassification', '应用分类')
			}}</span>
			<img src="./images/close.svg" @click="emits('closePopup', false)" />
		</header>
		<main id="popup-list" class="popup-list">
			<div
				class="popup-list-card"
				:class="{
					check: (cardIndex ?? activeIndex) === index,
				}"
				v-for="(item, index) in appList"
				@click="emits('changeCardIndex', index)"
			>
				<span>
					{{ item.group_name }}
				</span>
			</div>
			<div class="end-mask" :style="{ opacity: showEndMask ? '1' : '0' }"></div>
		</main>
		<footer class="popup-footer">
			<div class="button-group">
				<button @click="close">
					{{ $t('common.cancel', '取消') }}
				</button>
				<button @click="rollList">
					{{ $t('pages.application.determine', '确定') }}
				</button>
			</div>
		</footer>
	</div>
</template>
<script setup lang="ts">
import { ref, onMounted } from 'vue'
// import { t } from '@/entry_mobile/locales/index'
import { i18n } from '@/locales'
const { $t } = i18n
const emits = defineEmits(['closePopup', 'triggerClick', 'changeCardIndex'])
const props = defineProps(['appList', 'activeIndex', 'cardIndex'])
const showEndMask: any = ref(false)
const rollList = () => {
	emits('triggerClick', props.cardIndex ?? props.activeIndex)
	emits('changeCardIndex', null)
	emits('closePopup', false)
}
const close = () => {
	emits('changeCardIndex', null)
	emits('closePopup', false)
}
onMounted(() => {
	let popupList: any = document.getElementById('popup-list')
	showEndMask.value =
		popupList.scrollHeight - popupList.scrollTop - popupList.clientHeight > 2
	popupList.addEventListener('scroll', () => {
		showEndMask.value =
			popupList.scrollHeight - popupList.scrollTop - popupList.clientHeight > 2
	})
})
</script>
<style lang="less" scoped>
.popup-content {
	display: flex;
	flex-direction: column;
	align-items: center;
	padding: 20px 0 0 0;
	height: 100%;
	.popup-title {
		width: calc(100% - 32px);
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 24px;
		span {
			font-family: 'PingFang SC';
			font-style: normal;
			font-weight: 600;
			font-size: 14px;
			line-height: 20px;
			color: #1f2329;
		}
		img {
			width: 16px;
			height: 16px;
		}
	}
	.popup-list {
		position: relative;
		height: calc(100% - 140px);
		display: grid;
		grid-template-columns: repeat(2, 141px);
		grid-template-rows: repeat(auto-fill, 32px);
		grid-gap: 12px;
		overflow-y: scroll;
		margin-bottom: 2vh;
		.end-mask {
			pointer-events: none;
			position: fixed;
			z-index: 9;
			width: 100%;
			height: 76px;
			bottom: 95px;
			left: 0;
			background: linear-gradient(
				180deg,
				rgba(255, 255, 255, 0) 0%,
				#ffffff 100%
			);
			opacity: 0;
			transition: opacity 0.3s ease;
		}
		&::-webkit-scrollbar {
			display: none;
		}
		&-card {
			display: flex;
			justify-content: center;
			align-items: center;
			width: 141px;
			height: 32px;
			background: #f2f4f7;
			border: 1px solid #f2f4f7;
			border-radius: 4px;
			padding: 0 16px;
			span {
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
				font-family: 'PingFang SC';
				font-style: normal;
				font-weight: 400;
				font-size: 13px;
				color: #1f2329;
			}
		}
		.check {
			color: @rok-mobile-primary-color;
			border-color: @rok-mobile-primary-color;
			background: @rok-mobile-background-color;
		}
	}
	.popup-footer {
		bottom: 0;
		position: fixed;
		display: flex;
		justify-content: center;
		width: 100%;
		border-top: 1px solid #e8eaed;
		.button-group {
			margin-top: 2.3vh;
			margin-bottom: 2.3vh;
			button:first-child {
				width: 100px;
				height: 40px;
				background: #ffffff;
				border: 1px solid #dee0e3;
				border-radius: 4px;
				font-family: 'PingFang SC';
				font-style: normal;
				font-weight: 400;
				font-size: 16px;
				line-height: 24px;
				text-align: center;
				color: #1f2329;
				margin-right: 8px;
			}
			button:last-child {
				border: 0;
				width: 181px;
				height: 40px;
				background: @rok-mobile-primary-color;
				border-radius: 4px;
				font-family: 'PingFang SC';
				font-style: normal;
				font-weight: 400;
				font-size: 16px;
				line-height: 24px;
				text-align: center;
				color: #ffffff;
			}
		}
	}
}
</style>
